package com.hdu.clj.fitness

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_achievement.*

//展示成就
class AchievementActivity : AppCompatActivity() {

    private var achList= ArrayList<Ach>()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_achievement)

        //获取当前总跳绳数
        val dbHelper = userDatabase(this,"Users.db",1)
        val db = dbHelper.writableDatabase
        var cur_data = 0
        val curUserAcc = LoadAndSave().load("userAcc",this)
        var curUserData = db.rawQuery("select * from Users where acc = ?", arrayOf(curUserAcc))
        if (curUserData.moveToFirst()){
            cur_data = curUserData.getInt(curUserData.getColumnIndex("total"))
        }
        //加载成就
        initAch(cur_data)
        val adapter = AchAdapter(this,R.layout.ach_item,achList)
        achListView.adapter = adapter

    }

    private fun initAch(num: Int) {
        achList.clear()
        var achievement = Ach("","","",0)
        var text = ""
        var textcolor = ""
        var textsize = ""
        if (num>=0){
            text = "初入江湖 "
            textcolor = "#67A5AD"
            textsize = "20f"
            achList.add(Ach(text,textsize,textcolor,R.drawable.a1))
        }
        if (num>=1000){
            text = "小试牛刀 "
            textcolor = "#096C79"
            textsize = "20f"
            achList.add(Ach(text,textsize,textcolor,R.drawable.b2))
        }
        if (num>=5000){
            text = "小有所成 "
            textcolor = "#3F99E0"
            textsize = "22f"
            achList.add(Ach(text,textsize,textcolor,R.drawable.c3))
        }
        if (num>=10000){
            text = "声名鹊起"
            textcolor = "#3FD844"
            textsize = "22f"
            achList.add(Ach(text,textsize,textcolor,R.drawable.d4))
        }
        if (num>=15000){
            text = "风生水起"
            textcolor = "#8BC34A"
            textsize = "24f"
            achList.add(Ach(text,textsize,textcolor,R.drawable.e5))
        }
        if (num>=25000){
            text = "独占鳌头"
            textcolor = "#D0DF41"
            textsize = "24f"
            achList.add(Ach(text,textsize,textcolor,R.drawable.f6))
        }
        if (num>=45000){
            text = "平步青云"
            textcolor = "#E2D029"
            textsize = "26f"
            achList.add(Ach(text,textsize,textcolor,R.drawable.i9))
        }
        if (num>=80000){
            text = "名满天下"
            textcolor = "#F3CE5C"
            textsize = "26f"
            achList.add(Ach(text,textsize,textcolor,R.drawable.h8))
        }
        if (num>=100000){
            text = "举世无双"
            textcolor = "#FF5722"
            textsize = "27f"
            achList.add(Ach(text,textsize,textcolor,R.drawable.g7))
        }
        if (num>=150000){
            text = "一代宗师"
            textcolor = "#E22011"
            textsize = "27f"
            achList.add(Ach(text,textsize,textcolor,R.drawable.j10))
        }
        if (num>=200000){
            text = "飞升成仙"
            textcolor = "#EE1C63"
            textsize = "28f"
            achList.add(Ach(text,textsize,textcolor,R.drawable.k11))
        }
        if(num>=1000000){
            text = "臭不要脸"
            textcolor = "#3F51B5"
            textsize = "28f"
            achList.add(Ach(text,textsize,textcolor,R.drawable.l12))
        }
        val number = 12-achList.size
        if (number>0){
            repeat(number){
                achList.add(Ach("? ? ?","25f","#67A5AD",R.drawable.wz))
            }
        }


    }
}
